#
# @lc app=leetcode.cn id=198 lang=python3
#
# [198] 打家劫舍
#

# @lc code=start
class Solution:
    def rob(self, nums: List[int]) -> int:
        n = len(nums)
        if n == 0: return 0
        if n == 1: return nums[0]
        if n == 2: return max(nums[0], nums[1])
        sum = []
        sum.append(nums[0])
        sum.append(max(nums[0], nums[1]))
        for i in range(2, n):
            sum.append(max(sum[i - 2] + nums[i], sum[i - 1]))
        return sum[-1]

        
# @lc code=end

